package com.datas.service;

import com.datas.utils.hbn.HbnTxRuner;
import org.hibernate.Session;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by jige0727 on 2017/5/31.
 * 权限服务器
 */
@Service
public class PermissionService {
    /**
     * 获取能看的到的角色 id 列表
     *
     * @param userid
     * @return
     */
    public List<Integer> getUserCanseeRoleIds(Integer userid) {
        return (List<Integer>) new HbnTxRuner() {
            @Override
            protected Object dataLogic() throws Exception {
                return getUserCanseeRoleIds(userid, getCurrentSession());
            }
        }.run();
    }

    public List<Integer> getUserCanseeRoleIds(Integer userid, Session session) {
        String hql = "select ur.roles_id " +
                "from UmsUser_UmsRole ur " +
                "where ur.users_id=:userid ";
        return session.createQuery(hql)
                .setParameter("userid", userid)
                .list();
    }
}
